import 'amfe-flexible'
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import Cube from 'cube-ui'
import App from './App'
import router from './router'
import store from './store'
import zutil from './util/util'
import moment from 'moment'
import './util/directives.js'
import VConsole from 'vconsole'
import VueFab from 'vue-float-action-button'

import VsTree from 'vs-tree';
import 'vs-tree/lib/style/index.css';

require('./mock')

Vue.config.productionTip = false
Vue.use(Cube)
Vue.use(VueFab)
Vue.use(VsTree);

Vue.prototype.zutil = zutil;
Vue.prototype.moment = moment;

Vue.filter('time', function (value, type) {
  type = parseInt(type, 10);
  let formatString = '';
  switch (type) {
    case 1:
      formatString = 'YYYY-MM-DD HH:mm:ss';
      break;
    case 2:
      formatString = 'YYYY-MM-DD HH:mm';
      break;
    default:
      formatString = 'YYYY-MM-DD';
      break;
  }
  return moment(value).format(formatString);
})
Vue.filter('timef', function (value, formatString) {
  formatString = formatString || 'YYYY-MM-DD HH:mm';
  return moment(value).format(formatString);
})

Vue.filter('formatNum', function (value, type) {
  return (value+ '').replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
})

//价格过滤器{{v.price | priceFormat(2,'￥',true)}}
// arg表示原始参数,num表示小数点位,默认保留两位,symbol表示符号,spilt是否进行逗号分隔【true，false】
Vue.filter('priceFormat', function (arg,num=0,symbol,spilt=false) {
  /**
   * 默认数字: {{number|priceFormat()}}
    保留两位小数: {{number|priceFormat(2)}}
    保留三位小数: {{number|priceFormat(3)}}
    添加￥符号并保留两位: {{number|priceFormat(2,'￥')}}
    添加$符号并保留三位: {{number|priceFormat(3,'$')}}
    添加千分号符号: {{number|priceFormat(0,'',true)}}
    添加千分号符号并保留两位: {{number|priceFormat(2,'',true)}}
    添加￥和千分号符号并保留两位: {{number|priceFormat(2,'￥',true)}}
   **/
  arg=Number(arg).toFixed(num);
  if(spilt==true){
    if (arg.indexOf('.') == -1) {
      arg=arg.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    }else{
      var parts = arg.split(".");
      parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
      arg=parts.join(".");
    }
  }
  if(symbol){
    arg=symbol+arg;
  }
  return arg;
})

// if (process.env.NODE_ENV === 'production') {
if (process.env.NODE_ENV === 'development') {
  new VConsole()
}

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,//使用store
  template: '<App/>',
  components: { App }
})
